package com.example.hfiveandaplication.dialog;

import android.app.Dialog;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.ViewGroup;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

import com.barradata.R;


public class LoadingDialog extends Dialog implements ILoading {

    private SixLoading mSixLoading;

    public LoadingDialog(@NonNull Context context) {
        super(context);
        initViews(context);
    }

    public LoadingDialog(@NonNull Context context, int themeResId) {
        super(context, themeResId);
        initViews(context);
    }

    protected LoadingDialog(@NonNull Context context, boolean cancelable, @Nullable OnCancelListener cancelListener) {
        super(context, cancelable, cancelListener);
        initViews(context);
    }

    private void initViews(Context context) {
        ViewGroup rootView = (ViewGroup) LayoutInflater.from(context).inflate(R.layout.dialog_loading,null);
        mSixLoading = rootView.findViewById(R.id.dialog_overwatch);
        setContentView(rootView);

        setCancelable(false);
        setCanceledOnTouchOutside(false);
    }

    @Override
    public void showLoading() {
//        if (!overWatchLoading.startAnim()) {
//            Timer timer = new Timer();
//            TimerTask timerTask = new TimerTask() {
//                @Override
//                public void run() {
                    mSixLoading.startAnim();
//                }
//            };
//            timer.schedule(timerTask, 500);
//        }
        show();
    }

    @Override
    public void dismissLoading() {
        mSixLoading.stopAnim();
        dismiss();
    }
}
